// pages/MyComments/MyComments.js
const Controller = require('../controllers/controllers').controller;
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    title:'我的评论',
    myCommentList: [],
    lastPage: null,
    pageNumber: 1,
    myId: '',
    noData: false
  },
  // 获取评论数据
  myCommentList() { 
    Controller.myCommentList({
        page: this.data.pageNumber
      })
      .then(res => {
        console.log('获取评论数据', res)
        if (res) {
          let myCommentList = this.data.myCommentList;
          res.data.baseData.list.map(item => {
            item.createTime = app.getBeforeTime(item.createTime)
            myCommentList.push(item)
          })
          this.setData({
            myCommentList,
            lastPage: res.data.baseData.lastPage,
            pageNumber: res.data.baseData.pageNumber
          })
        }
      })
  },
  // 跳转到评论详情页
  goTocommentDetail(e) {
    console.log('跳转到评论详情页', e)
    let commentId = e.currentTarget.dataset.commentid
    let bodyId = e.currentTarget.dataset.bodyid
    let type = e.currentTarget.dataset.type
    let bodyType = e.currentTarget.dataset.bodytype
    /*if(type == 5){
      wx.navigateTo({
        url: '/pages/Comment/CommentDetail/CommentDetail?id=' + commentId + '&bodyId=' + bodyId+'&type='+type,
      })
    }else{
      wx.navigateTo({
         url: '/pages/Comment/Comment?rid=' + bodyId + '&type=' + bodyType,
      })
    }*/
    wx.navigateTo({
         url: '/pages/Comment/Comment?rid=' + bodyId + '&type=' + bodyType,
      })
  },
  // 跳转到评论详情页
  goCommentDetail(e) {
    console.log('跳转到评论详情页', e)
    let {
      bodyId,
      rid,
      type
    } = e.currentTarget.dataset
    if (type == 5) {
      wx.navigateTo({
        url: '/pages/Comment/CommentDetail/CommentDetail?bodyId=' + bodyId + '&rid' + rid,
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
    this.setData({
      myId: wx.getStorageSync('userInfos').id
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      myCommentList:[],
      pageNumber:1
    })
    this.myCommentList()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let that = this;
    if (!that.data.lastPage) {
      // 存在数据
      that.setData({
        pageNumber: that.data.pageNumber + 1
      })
      console.log('存在数据', that.data.pageNumber)
      that.myCommentList();

    } else {
      wx.showToast({
        title: '没有更多了',
        icon:"none"
      })
      this.setData({
        noData: true
      })
    }
  },

  onShareAppMessage: function (e) {
    // if (e.from == "button") {
      let obj = {
        title: '有氧FM·我的评论',
        success: function (res) {
          
        },
        fail(err) {
          
        }
      }
      return obj
    // }
  },
  onShareTimeline: function (e) {
    // if (e.from == "button") {
      let obj = {
        title: '有氧FM·我的评论',
        success: function (res) {
          
        },
        fail(err) {
          
        }
      }
      return obj
    // }
  },
})